package ${package.Controller};

<#if cfg.customPort == 'Y'>
import ${cfg.permissions};
import ${cfg.businessType};
import ${cfg.customLogs};
import ${cfg.customResult};
import ${cfg.baseController};
import ${package.Entity}.${entity};
</#if>
import ${package.Service}.${table.serviceName};
import io.swagger.v3.oas.annotations.tags.Tag;
<#if cfg.customPort == 'Y'>
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
</#if>
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.*;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
<#if cfg.customTable == 'Y'>
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile;
import com.cloud.utils.ExcelPoiUtils;
import java.util.ArrayList;
</#if>
<#if cfg.customPort == 'Y'>
import com.cloud.utils.ToolUtils;
import java.util.List;
</#if>

/**
 * ${table.comment!}
 *
 * @author ${author}
 * @since ${date}
 */
@Tag(name = "${table.comment!}")
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("/${cfg.simpleName}/${cfg.moduleName}")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName}<#if cfg.customPort == 'Y'> extends BaseController</#if> {
</#if>

    @Autowired
    private ${table.serviceName} ${'${table.serviceName}' ? substring(1) ? uncap_first};

<#if cfg.customPort == 'Y'>
    @Operation(summary = "${table.comment!}分页")
    @RequestPermissions("${cfg.simpleName}:${cfg.moduleName}:list")
    @GetMapping("/list")
    public Result list(${entity} ${'${entity}' ? uncap_first}) {
        startPage();
        List<${entity}> ${'${entity}' ? uncap_first}List = ${'${table.serviceName}' ? substring(1) ? uncap_first}.get${entity}List(${'${entity}' ? uncap_first});
        return getDataTable(${'${entity}' ? uncap_first}List);
    }

    @Operation(summary = "新增${table.comment!}")
    @Logs(title = "新增${table.comment!}", businessType = BusinessType.INSERT)
    @RequestPermissions("${cfg.simpleName}:${cfg.moduleName}:add")
    @PostMapping("/insert")
    public Result insert(@RequestBody ${entity} ${'${entity}' ? uncap_first}) {
        return toResult(${'${table.serviceName}' ? substring(1) ? uncap_first}.save${entity}(${'${entity}' ? uncap_first}));
    }

    @Operation(summary = "修改${table.comment!}")
    @Logs(title = "修改${table.comment!}",businessType = BusinessType.UPDATE)
    @RequestPermissions("${cfg.simpleName}:${cfg.moduleName}:edit")
    @PostMapping("/update")
    public Result update(@RequestBody ${entity} ${'${entity}' ? uncap_first}) {
        return toResult(${'${table.serviceName}' ? substring(1) ? uncap_first}.edit${entity}(${'${entity}' ? uncap_first}));
    }

    @Operation(summary = "${table.comment!}详情")
    @RequestPermissions("${cfg.simpleName}:${cfg.moduleName}:query")
    @GetMapping("/getInfo")
    public Result getInfo(Long id) {
        return Result.success("查询成功", ${'${table.serviceName}' ? substring(1) ? uncap_first}.get${entity}ById(id));
    }

    @Operation(summary = "删除${table.comment!}")
    @Logs(title = "删除${table.comment!}", businessType = BusinessType.DELETE)
    @RequestPermissions("${cfg.simpleName}:${cfg.moduleName}:remove")
    @PostMapping("/remove")
    public Result remove(String ids) {
        List<Long> list = ToolUtils.setIdsToList(ids);
        return toResult(${'${table.serviceName}' ? substring(1) ? uncap_first}.removeIds(list));
    }

</#if>
<#if cfg.customTable == 'Y'>
    @Operation(summary = "模板下载")
    @PostMapping("/template")
    public void template(HttpServletResponse response) {
        String titleName = "${table.comment!}模板";
        List<${entity}> dataList = new ArrayList<>();
        ExcelPoiUtils.exportExcel(dataList, titleName, "${table.name}",
        ${entity}.class, titleName + ".xls", response);
    }

    @Operation(summary = "${table.comment!}导入")
    @RequestPermissions("${cfg.simpleName}:${cfg.moduleName}:import")
    @PostMapping("/importData")
    public Result importData(@RequestParam("file") MultipartFile file) {
        return toResult(${'${table.serviceName}' ? substring(1) ? uncap_first}.importData(file));
    }

    @Operation(summary = "${table.comment!}导出")
    @RequestPermissions("${cfg.simpleName}:${cfg.moduleName}:export")
    @PostMapping("/export")
    public void export(${entity} ${'${entity}' ? uncap_first}) {
        ${'${table.serviceName}' ? substring(1) ? uncap_first}.export(${'${entity}' ? uncap_first});
    }
</#if>

}
</#if>
